<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>登录页面</title>

    <!-- Bootstrap Core CSS -->
    <link href="/AdminCss/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="/AdminCss/bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="/AdminCss/dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="/AdminCss/bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                @if(session('error'))
                    <div class="alert alert-danger alert-dismissable">
                        <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                        {{session('error')}}
                    </div>
                @endif
                <div class="login-panel panel panel-default">
                    <div class="panel-heading">
                        <center><h3 class="panel-title"><b>登录</b></h3></center>
                    </div>
                    <div class="panel-body">
                        <form role="form" action="{{ url('admin/login/insert') }}" method='post'>
                            <fieldset>
                                <div class="form-group">
                                    <input class="form-control" placeholder="用户名" name="username" type="text" autofocus>
                                    <span></span>
                                </div>

                                <div class="form-group">
                                    <input class="form-control" placeholder="密码" name="password" type="password" value="" >
                                    <span></span>
                                </div>
                                <!-- Change this to a button or input when using this as a form -->
                                {{csrf_field()}}
                                <button class="btn btn-lg btn-success btn-block">登录</button>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- jQuery -->
    <script src="/AdminCss/bower_components/jquery/dist/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="/AdminCss/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="/AdminCss/bower_components/metisMenu/dist/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="/AdminCss/dist/js/sb-admin-2.js"></script>
    <script type="text/javascript">
    //声明全局变量
    var CUSER = false;
    var CPASS = false;
    //绑定表单事件
    $('form').submit(function(){
        //触发所有的丧失焦点事件
        $('input').trigger('blur');
        //判断是否全部成功
        if(CUSER && CPASS){
            return true;
        }

        return false;
    });
    //给所有的字段绑定获取焦点事件
    $('input').focus(function(){
        //获取属性 提示信息
        var readmin = $(this).attr('readmin');
        //给后面的span标签修改文本
        $(this).next().html(readmin).css('color','blue');
        $(this).css('border','1px solid blue'); 
    }) 
    //检查用户名
    $('input[name=username]').blur(function(){
        //检查用户名是否为空
        if($(this).val() == ''){ 
            $(this).next().html('*用户名不能为空').css('color','red');
            $(this).css('border','1px solid red');
            return false;
        }
        var uname=$(this).val();
        var inp=$(this);
        $.get('/admin/login/check',{username:uname},function(data){
            // console.log(data);
            if(data==0){
              inp.next().html('*该用户不存在!').css('color','red');
              inp.css('border','1px solid red');
              return false;  
            }else{
              inp.next().html('√').css('color','green');
              inp.css('border','1px solid green');
              CUSER = true; 
            }
        });
    });


    //确认密码
    $('input[name=password]').blur(function(){
        //判断密码是否为空
        if($(this).val() == ''){ 
            $(this).next().html('*密码不能为空').css('color','red');
            $(this).css('border','1px solid red');
            return false;
        } 
        //判断输入密码是否符合要求
        var pass=$(this).val();
        var reg = /\w{6,18}/;       

        if(reg.test(pass)){
            $(this).next().html('√').css('color','green');
            $(this).css('border','1px solid green');
            CPASS = true;
        }else{
            $(this).next().html('密码格式不正确').css('color','red');
            $(this).css('border','1px solid red');
            CPASS = false;
        }
    });
    </script>

</body>

</html>
